/*
 * Powered By [rapid-framework]
 * Web Site: http://www.rapid-framework.org.cn
 * Google Code: http://code.google.com/p/rapid-framework/
 * Since 2008 - 2012
 */

package com.tech15.pub.model;

import java.util.HashSet;
import java.util.Set;

import javacommon.base.BaseEntity;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.validator.constraints.Length;

/**
 * @author 胡作正 email:zuozhenghu@sina.com
 * @version 1.0
 * @since 1.0
 */


@Entity
@Table(name = "PUB_DATA")
public class PubData extends BaseEntity implements java.io.Serializable{
	private static final long serialVersionUID = 5454155825314635342L;
	
	//alias
	public static final String TABLE_ALIAS = "PubData";
	public static final String ALIAS_ID = "序号";
	public static final String ALIAS_NAME = "名称";
	public static final String ALIAS_PID = "父id";
	
	//date formats
	

	//可以直接使用: @Length(max=50,message="用户名长度不能大于50")显示错误消息
	//columns START
    /**
     * 序号       db_column: ID 
     */ 	
	
	private Long id;
    /**
     * 名称       db_column: NAME 
     */ 	
	@Length(max=150)
	private java.lang.String name;
    /**
     * 父id       db_column: PID 
     */ 	
	
	private Long pid;
	/**
     * 排序       db_column: SORTNO 
     */ 	
	
	private Integer sortno;
	
	private Integer issys;
	
	private String bz;
	//columns END


	public PubData(){
	}

	public PubData(
		Long id
	){
		this.id = id;
	}

	

	public void setId(Long value) {
		this.id = value;
	}
	
	@Id @GeneratedValue(generator="custom-id")
	@GenericGenerator(name="custom-id", strategy = "increment")
	@Column(name = "ID", unique = true, nullable = false, insertable = true, updatable = true, length = 22)
	public Long getId() {
		return this.id;
	}
	
	@Column(name = "NAME", unique = false, nullable = true, insertable = true, updatable = true, length = 150)
	public java.lang.String getName() {
		return this.name;
	}
	
	public void setName(java.lang.String value) {
		this.name = value;
	}
	
	@Column(name = "BZ", unique = false, nullable = true, insertable = true, updatable = true, length = 300)
	public java.lang.String getBz() {
		return this.bz;
	}
	
	public void setBz(java.lang.String value) {
		this.bz = value;
	}
	
	@Column(name = "PID", unique = false, nullable = true, insertable = true, updatable = true, length = 22)
	public Long getPid() {
		return this.pid;
	}
	
	public void setPid(Long value) {
		this.pid = value;
	}
	
	@Column(name = "SORTNO", unique = false, nullable = true, insertable = true, updatable = true, length = 5)
	public Integer getSortno() {
		return this.sortno;
	}
	
	public void setSortno(Integer value) {
		this.sortno = value;
	}
	
	@Column(name = "ISSYS", unique = false, nullable = true, insertable = true, updatable = true, length = 2)
	public Integer getIssys() {
		return this.issys;
	}
	
	public void setIssys(Integer value) {
		this.issys = value;
	}
	
	
	private Set pubDatas = new HashSet(0);
	public void setPubDatas(Set<PubData> pubData){
		this.pubDatas = pubData;
	}
	
	@OneToMany(cascade = { CascadeType.MERGE }, fetch = FetchType.LAZY, mappedBy = "pubData")
	@OrderBy(value = "sortno ASC")
	public Set<PubData> getPubDatas() {
		return pubDatas;
	}
	
	private PubData pubData;
	public void setPubData(PubData pubData){
		this.pubData = pubData;
	}
	
	@ManyToOne(cascade = {}, fetch = FetchType.LAZY)
	@JoinColumns({
		@JoinColumn(name = "PID",nullable = false, insertable = false, updatable = false) 
	})
	public PubData getPubData() {
		return pubData;
	}
	

	public String toString() {
		return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
			.append("Id",getId())
			.append("Name",getName())
			.append("Pid",getPid())
			.toString();
	}
	
	public int hashCode() {
		return new HashCodeBuilder()
			.append(getId())
			.toHashCode();
	}
	
	public boolean equals(Object obj) {
		if(obj instanceof PubData == false) return false;
		if(this == obj) return true;
		PubData other = (PubData)obj;
		return new EqualsBuilder()
			.append(getId(),other.getId())
			.isEquals();
	}
}

